package org.lzfto.flink.demo.common.result;

public class PubResult<T> {
	/**
	 * 常规消息
	 */
	public static final int MESSAGE_TYPE_NORMAL=1;
	/**
	 * 任务已经完成
	 */
	public static final int MESSAGE_TYPE_JOB_ISFINISHED=2;

	private Integer    flag;
    private String     message;
    private Integer    stageType;
    private T data;
    private String receiver;
    /**
     * data是否为对象类型，而不是原生类型/原生类型的包装类
     * </br>通常不需要设置，主要用于前端
     */
    private Boolean dataIsObject;
    

    public String getReceiver() {
		return receiver;
	}

	public Integer getStageType() {
		return stageType;
	}

	public String getMessage() {
        return message;
    }

    public Integer getFlag() {
        return flag;
    }

    public T getData() {
        return data;
    }

    public Boolean getDataIsObject() {
        return dataIsObject;
    }

    public void setDataIsObject(Boolean dataIsObject) {
        this.dataIsObject = dataIsObject;
    }

    public PubResult() {
    }

    public PubResult(Integer flag, String message, T data) {
        this.flag = flag;
        this.message = message;
        this.data = data;
        this.stageType =MESSAGE_TYPE_NORMAL;
        this.dataIsObject=false;
    }
    
    public static  <T> PubResult<T> ok_data(T data) {
        PubResult<T> result = new PubResult<>(1, "成功", data);
        return result;
    }

    public static  <T> PubResult<T> ok(String message) {
        PubResult<T> result = new PubResult<T>(1, message, null);
        return result;
    }

    public static  <T> PubResult<T> ok(String message, T data) {
        PubResult<T> result = new PubResult<T>(1, message, data);
        return result;
    }

    public static  <T> PubResult<T> error(String message) {
        PubResult<T> result = new PubResult<T>(0, message, null);
        return result;
    }
    
    @SuppressWarnings({ "hiding", "unchecked" })
	public <T> PubResult<T> withStageType(Integer stageType){
    	this.stageType =stageType;
    	return (PubResult<T>) this;
    }
    
    @SuppressWarnings({ "unchecked", "hiding" })
	public <T> PubResult<T> withReceiver(String receiver) {
    	this.receiver=receiver;
    	return (PubResult<T>) this;
    }
    
    @SuppressWarnings({ "unchecked", "hiding" })
   	public <T> PubResult<T> withDataIsObject(Boolean dataIsObject) {
       	this.dataIsObject=dataIsObject;
       	return (PubResult<T>) this;
       }
}
